﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EnterpriseFund.Common;

namespace EnterpriseFund.Controllers
{
    [OutputCache(Duration = 0, VaryByParam = "none")]   
    public class DSImportDateController : AdminBaseController 
    {
        [AuthorityActionFilter("m_DSImportDate", Order = 1)]
        [LogPageActionFilter("地税数据导入", Order = 2)]
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 地税数据导入
        /// </summary>
        /// <returns>视图</returns>
        [AuthorityActionFilter("m_DSImportDate", Order = 1)]
        [LogPageActionFilter("地税数据导入", Order = 2)]
        public ActionResult DSImportDateEdit()
        {
            return View();  
        }

        public string DSImportDate(string beginDate, string endDate)
        {
            try
            {
                DateTime d1=new DateTime();
                DateTime d2=new DateTime();
                if (DateTime.TryParse(beginDate, out d1))
                {
                    if (DateTime.TryParse(endDate, out d1))
                    {
                        string endDateor = DateTime.Parse(endDate).AddDays(1).ToString("yyyy-MM-dd");
                        string strwhere = " datediff(DAY,'" + beginDate + "',sjrq ) >=0 and datediff(DAY,'" + endDate + "',sjrq )<=0";
                        string strwhere2 = " datediff(DAY,'" + beginDate + "',xhrq ) >=0 and datediff(DAY,'" + endDate + "',xhrq )<=0";
                        string orastrwhere = "  a.nsrdzdah = b.nsrdzdah   and sjrq >= date '" + beginDate + "' and sjrq < date '" + endDateor + "' and rkrq is not null ";
                        string orastrwhere2 = " a.nsrdzdah = b.nsrdzdah and xhrq >= date '" + beginDate + "' and xhrq < date '" + endDateor + "' and zfrq is null ";
                        orastrwhere += " and b.skss_swjg_dm like '2330209%' order by sjrq ";
                        orastrwhere2 += " and a.nsr_swjg_dm like '2330209%' ";
                        BLL.SB_ZSXX SB_ZSXXBLL = new BLL.SB_ZSXX();
                        SB_ZSXXBLL.ImportData(strwhere, strwhere2, orastrwhere, orastrwhere2);
                        return "ok";
                    }
                    else
                    {
                        return "结束时间输入有误";
                    }
                }
                else
                {
                    return "开始时间输入有误";
                }
          
            }
            catch(Exception ex)
            {
                if (ex.Message == "税款总额不一致" || ex.Message == "税款总额出错")
                {
                    return ex.Message;
                }
                else
                {
                    return ex.Message;
                }
            }
        }

    }
}
